package com.hyh.prize.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hyh.prize.service.TabSaleplanGiftlogService;
import com.lww.springcloudapi.entity.TabGgcardEncash;
import com.lww.springcloudapi.entity.TabSaleplanGiftlog;
import com.lww.springcloudapi.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 * 营销礼品异动表 前端控制器
 * </p>
 *
 * @author SHEN
 * @since 2021-03-11
 */
@RestController
@RequestMapping("/admin/prize/giftlog/")
@Api(tags = "营销礼品异动表操作模块")
public class TabSaleplanGiftlogController {

    @Resource
    private TabSaleplanGiftlogService tabSaleplanGiftlogService;

    @PostMapping("add")
    @ApiOperation("新增营销礼品异动记录")
    public Result addGiftlog(@RequestBody TabSaleplanGiftlog tabSaleplanGiftlog){
        boolean save = tabSaleplanGiftlogService.save(tabSaleplanGiftlog);
        if(save){
            return Result.ok();
        }
        return Result.fail();
    }

    @PostMapping("list/{current}/{limit}")
    @ApiOperation(value = "分页查询营销礼品异动表")
    public Result getList(@PathVariable long current,
                          @PathVariable long limit,
                          @RequestBody(required = false) TabSaleplanGiftlog tabSaleplanGiftlog){
//        Page<TabSaleplanGiftlog> page=new Page(current,limit);
//        QueryWrapper<TabSaleplanGiftlog> queryWrapper=new QueryWrapper<>();
//        if(tabSaleplanGiftlog.getAreaid()!=null){
//            queryWrapper.eq("ACPTSITEID",tabSaleplanGiftlog.getAreaid());
//        }
//
//        Page<TabSaleplanGiftlog> tabSaleplanGiftlogPage = tabSaleplanGiftlogService.page(page, queryWrapper);
        return Result.ok(tabSaleplanGiftlogService.getList(current,limit,tabSaleplanGiftlog));
    }

    @DeleteMapping ("delete/{id}")
    @ApiOperation(value = "删除营销礼品异动记录")
    public Result deleteEncash(long id){
        tabSaleplanGiftlogService.removeById(id);
        return Result.ok();
    }

    @DeleteMapping ("update")
    @ApiOperation(value = "修改营销礼品异动记录")
    public Result updateEncash(@RequestBody TabSaleplanGiftlog tabSaleplanGiftlog){
        boolean update = tabSaleplanGiftlogService.updateById(tabSaleplanGiftlog);
        if(update){
            return Result.ok();
        }
        return Result.fail();

    }
}

